package com.cc.pms.controller;

import com.cc.pms.service.*;
import com.cc.common.annotation.Anonymous;
import com.cc.pms.domain.vo.TagVo;
import com.cc.pms.domain.vo.TeamMemberVo;
import com.cc.pms.domain.vo.TeamTagVo;
import com.cc.pms.domain.vo.TeamVo;
import com.cc.common.core.domain.R;
import com.cc.common.core.page.PageQuery;
import com.cc.common.core.page.PageVo;
import com.cc.pms.domain.Tag;
import com.cc.pms.domain.TagType;
import com.cc.pms.domain.Team;
import com.cc.pms.domain.TeamMember;
import com.cc.pms.service.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/admin")
public class AdminController {

    @Resource
    private ITagTypeService tagTypeService;

    @Resource
    private ITagService tagService;

    @Resource
    private ITeamTagService iTeamTagService;

    @Resource
    private ITeamService iTeamService;

    @Resource
    private ITeamMemberService iTeamMemberService;


    @GetMapping("/tag/type/list")
    public R<PageVo<TagType>> tagTypeList(PageQuery query , TagType tagType){
        return R.ok(tagTypeService.pageVo(tagType ,query));
    }

    @PostMapping("/tag/type/create")
    public R<Long> createTagType(@RequestBody TagType tagType){
        return tagTypeService.create(tagType);
    }

    @PostMapping("/tag/type/update")
    public R<Boolean> updateTagType(@RequestBody TagType tagType){
        return tagTypeService.update(tagType);
    }

    @PostMapping("/tag/type/delete")
    public R<Boolean> updateTagType(@RequestBody Long[] ids){
        return tagTypeService.delete(ids);
    }


    @GetMapping("/tag/type/{tagTypeId}")
    public R<TagType> queryTagTypeById(@PathVariable Long tagTypeId){
        return R.ok(tagTypeService.getById(tagTypeId));
    }


    @Anonymous
    @GetMapping("/tag/list")
    public R<PageVo<TagVo>> tagList(PageQuery query , Tag tag){
        return R.ok(tagService.pageVo(tag ,query));
    }

    @PostMapping("/tag/create")
    public R<Long> createTag(@RequestBody Tag tag){
        return tagService.create(tag);
    }

    @PostMapping("/tag/update")
    public R<Boolean> updateTag(@RequestBody Tag tag){
        return tagService.update(tag);
    }

    @PostMapping("/tag/delete")
    public R<Boolean> updateTag(@RequestBody Long[] ids){
        return tagService.delete(ids);
    }

    @GetMapping("/team/list")
    public R<PageVo<TeamVo>> teamList(PageQuery query , Team team , String beginTime , String endTime){
       return R.ok(iTeamService.queryTeamVoPage(query, team, beginTime, endTime));
    }

    @GetMapping("/team/{teamId}/tags/list")
    public R<List<TeamTagVo>> teamTagsList(@PathVariable Long teamId){
        return R.ok(iTeamTagService.queryTeamTagVoByTeamId(teamId));
    }


    @GetMapping("/team/{teamId}/members/list")
    public R<List<TeamMemberVo>> teamMembersList(@PathVariable Long teamId){
        return R.ok(iTeamMemberService.queryTeamMemberVo(teamId));
    }


    @PostMapping("/team/{teamId}/disband")
    public R<Boolean> teamDisband(@PathVariable Long teamId){
        return iTeamService.disbandTeam(teamId);
    }


    @PostMapping("/team/update")
    public R<Boolean> teamUpdate(@RequestBody Team team){
        return iTeamService.updateTeam(team);
    }

    @PostMapping("/team/member/{teamId}/remove")
    public R<Boolean> teamMemberRemove(@PathVariable Long teamId ,@RequestBody Long[] ids){
        return iTeamMemberService.removeMembers(teamId, ids);
    }

    @PostMapping("/team/member/set-captain")
    public R<Boolean> teamMemberSetCaptain(@RequestBody TeamMember teamMember){
        iTeamMemberService.setCaptain(teamMember);
        return R.ok();
    }

    @PostMapping("/team/{teamId}/update-tags")
    public R<Boolean> updateTeamTags(@PathVariable Long teamId ,@RequestBody Long[] ids){
        return  iTeamTagService.updateTags(teamId , ids);
    }

}
